﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using Axelerate.Silverlight3D.Media.Media3D;

namespace SharePointTagCloud.Silverlight
{
    public class Tag3D
    {
        public Tag3D(double x, double y, double z, string text, Color tagColor)
        {
            centerPoint = new Point3D(x, y, z);
            textBlock = new TextBlock();
            textBlock.Text = text;
            btnLink = new HyperlinkButton();
            btnLink.Content = textBlock;
            this.TagColor = tagColor;

        }

        public HyperlinkButton btnLink { get; set; }

        public TextBlock textBlock { get; set; }

        public Point3D centerPoint { get; set; }

        private Color TagColor { get; set; }

        public void Redraw(double xOffset, double yOffset)
        {
            double zFactor = ((centerPoint.Z + 300) / 450.0);
            btnLink.FontSize = 30.0 * zFactor;
            double alpha = zFactor * 255;
            //Debug.WriteLine("Z: {0}; zFactor: {1}; alpha: {2}", centerPoint.Z, zFactor, alpha);
            btnLink.Foreground = new SolidColorBrush(Color.FromArgb(Convert.ToByte(alpha), TagColor.R, TagColor.G, TagColor.B));

            Canvas.SetLeft(btnLink, centerPoint.X + xOffset - (btnLink.ActualWidth / 2));
            Canvas.SetTop(btnLink, -centerPoint.Y + yOffset - (btnLink.ActualHeight / 2));
            Canvas.SetZIndex(btnLink, Convert.ToInt32(centerPoint.Z));

            /*
            double posZ = centerPoint.Z + 200;
            btnLink.FontSize = 10 * (posZ / 100);
            double alpha = centerPoint.Z + 200;
            if (alpha > 255)
                alpha = 255;

            if (alpha < 0)
                alpha = 0;

            btnLink.Foreground = new SolidColorBrush(Color.FromArgb(Convert.ToByte(alpha), 0, 0, 0));
            Canvas.SetLeft(btnLink, centerPoint.X + xOffset - (btnLink.ActualWidth / 2));
            Canvas.SetTop(btnLink, -centerPoint.Y + yOffset - (btnLink.ActualHeight/ 2));
            Canvas.SetZIndex(btnLink, Convert.ToInt32(centerPoint.Z));
             */
        }
    }
}
